Imports OMANE.Common.UI
Imports System.Collections.ObjectModel
Imports System.Windows
Imports Infragistics.Windows.Chart
Imports System.Windows.Controls
Imports System.ComponentModel
Imports PTIC_GestionBDD
Imports System.Collections.Specialized
Imports Microsoft.Practices.Prism.Commands

Namespace Zones
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    <EditableZone(), Serializable()> _
    Public Class TextZone
        Inherits ViewModelBase
        Implements ICloneable
        Implements IXelementSerializable



        Private _ValueSource As String
        Private _Value As String
        Private _FontSize As Double = 12
        Private _FontBrush As Media.Color
        Private _Police As Police = Indicateurs.Police.Default
        Private _Padding As Double

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        <EditableProperty(Group:="Visual")> _
        Public Property ValueSource As String
            Get
                Return _ValueSource
            End Get
            Set(ByVal value As String)
                OnPropertyChanging("ValueSource")
                _ValueSource = value
                OnPropertyChanged("ValueSource")
            End Set
        End Property

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        <EditableProperty(Group:="Visual")> _
        Public Property Value As String
            Get
                Return _Value
            End Get
            Set(ByVal value As String)
                OnPropertyChanging("Value")
                _Value = value
                OnPropertyChanged("Value")
            End Set
        End Property

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        <EditableProperty(Group:="Visual")> _
        Public Property FontBrush As Media.Color
            Get
                Return _FontBrush
            End Get
            Set(ByVal value As Media.Color)
                OnPropertyChanging("FontBrush")
                _FontBrush = value
                OnPropertyChanged("FontBrush")
            End Set
        End Property

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <EditableProperty(Group:="Visual")> _
        Public Property Padding As Double
            Get
                Return _Padding
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("Padding")
                _Padding = value
                OnPropertyChanged("Padding")
            End Set
        End Property

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <EditableProperty(Group:="Visual")> _
        Public Property Police As Police
            Get
                Return _Police
            End Get
            Set(ByVal value As Police)
                OnPropertyChanging("Police")
                _Police = value
                OnPropertyChanged("Police")
            End Set
        End Property

        <EditableCommand()> _
        Public Sub DoNothing(ByVal t As Object)
            MessageBox.Show("Don't think you are, know you are.")
        End Sub

        Private Function Clone() As Object Implements System.ICloneable.Clone
            Return New TextZone() With {
                ._FontBrush = _FontBrush,
                ._FontSize = _FontSize,
                ._Padding = _Padding,
                ._Police = New Police() With {
                    .IsBold = _Police.IsBold,
                    .IsItalic = _Police.IsItalic,
                    .FontString = _Police.FontString,
                    .Size = _Police.Size,
                    .Format = _Police.Format},
                ._Value = _Value
            }
        End Function

        Public Function ToXElement(ByVal options As Object) As System.Xml.Linq.XElement Implements IXelementSerializable.ToXElement
            Dim x = <TextZone
                        ValueSource=<%= ValueSource %>
                        FontBrush=<%= FontBrush %>
                        Padding=<%= Padding %>
                        IsBold=<%= Police.IsBold %>
                        IsItalic=<%= Police.IsItalic %>
                        Font=<%= Police.FontString %>
                        FontSize=<%= Police.Size %>>
                        <%= Value %>
                    </TextZone>

            Return x
        End Function

        Public Sub FromXElement(ByVal options As Object, ByVal x As System.Xml.Linq.XElement) Implements IXelementSerializable.FromXElement
            Dim cd = Function(s As String) Double.Parse(s, Globalization.CultureInfo.InvariantCulture)
            Dim cc = Function(s As String) Media.ColorConverter.ConvertFromString(s)
            Dim ct = Function(s As String) (New Windows.ThicknessConverter()).ConvertFromInvariantString(s)

            ValueSource = x.@ValueSource
            FontBrush = cc(x.@FontBrush)
            Padding = cd(x.@Padding)
            Police.IsBold = x.@IsBold
            Police.IsItalic = x.@IsItalic
            Police.FontString = x.@Font
            Police.Size = cd(x.@FontSize)
            Value = x.Value
        End Sub
    End Class
End Namespace
